*Table A.41: Correlation between BMI (z-score), 24-hour dietary recall, and supermarket choice tool: Adults
cd ""

use "master_data_adults_child_s13456_shared.dta", clear 
joinby id session using "Supermarket_data_short_S56_EDIandESSEX_STATA.dta", unmatched(both)

drop meal_control snack_control
gen meal_control=1 if treatment==2
replace meal_control=0 if treatment==1

gen snack_control=1 if treatment==3
replace snack_control=0 if treatment==1

drop if type_id=="X" // **Dropping newborns born during the three years of study
drop if id=="3885553B" //**error in the id number and empty data
drop if id=="3885553G" //**error in the id number and empty data
replace treatment=2 if id=="38855553B" //**retrieving the correct treatment for this id
replace treatment=2 if id=="38855553G" //**retrieving the correct treatment for this id
drop if id=="101aa22c" //**this id does not exist
drop if id=="27655663" //**outlier on many measurements

*variables created
ge food15_other_veg_new=food15_other_veg
replace food15_other_veg_new=0 if food15_other_veg==. & energykcal!=.

ge food16_fruit_new=food16_fruit
replace food16_fruit_new=0 if food16_fruit==. & energykcal!=.

su food15_other_veg 
su food16_fruit 
su food15_other_veg_new 
su food16_fruit_new

drop portion_veg_wisp portion_fruit_wisp
gen portion_veg_wisp=food15_other_veg/80
gen portion_fruit_wisp=food16_fruit/80
gen fuit_and_veg_g=total_veg_fruit_eatwell if session==1
replace fuit_and_veg_g=total_veg_fruit_eatwell if session==3
replace fuit_and_veg_g=food15_other_veg+food16_fruit if session==4

ge FV=food15_other_veg_new+food16_fruit_new

* Self reported changes in fruit and vegetables consumption
* adults
* simply counting changes (no change is equal to 0, decreases are negative, increases are positive)
gen n_change_FV=consumption_fresh_fruit+consumption_fresh_vegetables-4
gen n_change_fat=consumption_processed_meat+consumption_fried+consumption_burgers_pizza+consumption_crisps+consumption_veg_crisps+consumption_salted_peanuts+consumption_unsalted_nuts+consumption_pretzels_crackers-16
gen n_change_sugar=consumption_pies+consumption_cakes+consumption_doughnut+consumption_candies+consumption_ice_cream+consumption_energy_bar+consumption_breakfast_bar+consumption_soft_drinks-16
* different variable for session 3
replace n_change_FV=change_cons_fresh_fruit+change_cons_fresh_vegetables-4 if session==3
replace n_change_fat=change_cons_processed_meat+change_cons_fried+change_cons_burgers_pizza+change_cons_crisps+change_cons_veg_crisps+change_cons_salted_peanuts+change_cons_unsalted_nuts+change_cons_pretzels_crackers-16 if session==3
replace n_change_sugar=change_cons_pies+change_cons_cakes+change_cons_doughnut+change_cons_candies+change_cons_ice_cream+change_cons_energy_bar+change_cons_breakfast_bar+change_cons_soft_drinks-16 if session==3

* children
* simply counting changes (no change is equal to 0, decreases are negative, increases are positive)
gen child_n_change_FV=child_consumption_fresh_fruit+child_consumption_fresh_vegetabl-4
gen child_n_change_fat=child_consumption_processed_meat+child_consumption_fried+child_consumption_burgers_pizza+child_consumption_crisps+child_consumption_veg_crisps+child_consumption_salted_peanuts+child_consumption_unsalted_nuts+child_consumption_pretzels_crack-16
gen child_n_change_sugar=child_consumption_pies+child_consumption_cakes+child_consumption_doughnut+child_consumption_candies+child_consumption_ice_cream+child_consumption_energy_bar+child_consumption_breakfast_bar+child_consumption_soft_drinks-16
*session 3
replace child_n_change_FV=child_change_cons_fresh_fruit+child_change_cons_fresh_vegetabl-4 if session==3
replace child_n_change_fat=child_change_cons_processed_meat+child_change_cons_fried+child_change_cons_burgers_pizza+child_change_cons_crisps+child_change_cons_salted_peanuts+child_change_cons_veg_crisps+child_change_cons_unsalted_nuts+child_change_cons_pretzels_crack-16 if session==3
replace child_n_change_sugar=child_change_cons_pies+child_change_cons_cakes+child_change_cons_doughnut+child_change_cons_candies+child_change_cons_ice_cream+child_change_cons_energy_bar+child_change_cons_breakfast_bar+child_change_cons_soft_drinks+child_energy_drinks-16 if session==3

*assigning the values to children (they were in the row for adults)
bys hh_id session: egen child_TOT_n_change_FV=mean(child_n_change_FV)
bys hh_id session: egen child_TOT_n_change_fat=mean(child_n_change_fat)
bys hh_id session: egen child_TOT_n_change_sugar=mean(child_n_change_sugar)
replace n_change_FV=child_TOT_n_change_FV if child==1
replace n_change_fat=child_TOT_n_change_fat if child==1
replace n_change_sugar=child_TOT_n_change_sugar if child==1

* supermarket variables
* children
* replicate values for changes in child consumption (originally in adult survey) for child row in data
bys hh_id session: egen child_shop_fruit_veg_spend=mean(shop_fruit_veg_spend)
bys hh_id session: egen child_shop_unhealthy_spend=mean(shop_unhealthy_spend)
bys hh_id session: egen child_shop_fruit_veg_spend_perc=mean(shop_fruit_veg_spend_perc)
bys hh_id session: egen child_shop_unhealthy_spend_perc=mean(shop_unhealthy_spend_perc)
bys hh_id session: egen child_shop_calories=mean(shop_calories)
bys hh_id session: egen child_shop_fat_spend=mean(shop_fat)
bys hh_id session: egen child_shop_saturates=mean(shop_saturates)
bys hh_id session: egen child_shop_sugar=mean(shop_sugar)
bys hh_id session: egen child_shop_spending=mean(shop_spending)

replace shop_fruit_veg_spend=child_shop_fruit_veg_spend if child==1
replace shop_unhealthy_spend=child_shop_unhealthy_spend if child==1
replace shop_fruit_veg_spend_perc=child_shop_fruit_veg_spend_perc if child==1
replace shop_unhealthy_spend_perc=child_shop_unhealthy_spend_perc if child==1
replace shop_calories=child_shop_calories if child==1
replace shop_fat=child_shop_fat if child==1
replace shop_saturates=child_shop_saturates if child==1
replace shop_sugar=child_shop_sugar if child==1
replace shop_spending=child_shop_spending if child==1

* keeping all variables relevant to sugar consumption
generate calories1=energykcal
generate calories2=shop_calories
generate sugar1=nmesg
generate sugar2=shop_sugar
generate sugar3=n_change_sugar
generate FV1=FV
generate FV2=shop_fruit_veg_spend
generate FV3=n_change_FV
generate fat1=saturatesg
generate fat2=shop_fat
generate fat3=n_change_fat

drop id
rename id_nb id

*Adults 
*Calories 1 and 2
pwcorr bmi calories1 calories2 if child==0 & (session==5 | session==6), sig

*Sugar 1 (24-hr), 2 (supermarket) and 3 (self-rep)
pwcorr bmi sugar1 sugar3 sugar2 if child==0 & (session==5 | session==6), sig

*Fat 1 (24-hr), 2 (supermarket) and 3 (self-rep)
pwcorr bmi fat1 fat3 fat2 if child==0 & (session==5 | session==6), sig

*FV 1 (24-hr), 2 (supermarket) and 3 (self-rep)
pwcorr bmi FV1 FV3 FV2 if child==0 & (session==5 | session==6), sig
